package com.badger.pattern;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * 装饰者模式
 * @author liqi
 *
 */
public class TestDecorator {

    public static void main(String[] args) {
        GoddessGame goddess = new GoddessGame() {
            @Override
            String goods() {
                return "Dress";
            }
        };
        goddess = new Handbag(goddess);
        goddess = new Lipstick(goddess);
        goddess = new Handbag(goddess);
        System.out.println(goddess.goods());

        try (BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(new File("D:\\springwind\\test.txt"))));) {
            bw.write("我是装饰者模式！");
            bw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

abstract class GoddessGame {
    abstract String goods();
}

abstract class Decorator extends GoddessGame {
}

class Handbag extends Decorator {
    GoddessGame goddess;

    public Handbag(GoddessGame goddess) {
        this.goddess = goddess;
    }

    @Override
    String goods() {
        return goddess.goods() + ",Handbag";
    }
}

class Lipstick extends Decorator {
    GoddessGame goddess;

    public Lipstick(GoddessGame goddess) {
        this.goddess = goddess;
    }

    @Override
    String goods() {
        return goddess.goods() + ",Lipstick";
    }
}